<?php

require_once BASEDIR . 'lib/classes/sql.php';
$sql = new Sql();

$json = false;

if ( isset( $_POST['json'] ) )
	$json = json_decode( stripslashes( $_POST['json'] ), true );

if ( is_array( $json ) === false )
	$json = false;
else
{
	$time = time();

	foreach ($json as $key => $value) {
		if ( is_array( $json[ $key ] ) === false )
		{
			$json = false;
			break;
		}
		$strings[ $key ] = array(
			"data"			=>	$value,
			"type"			=>	"static",
			"last_update"	=>	$time
		);
	}
}

if ( $json !== false )
{
	if ( isset( $_POST['default'] ) )
		$default = stripslashes( $_POST['default'] );

	if ( !isset( $json[ $default ] ) ) {
		foreach ($json as $key => $value) {
			$default = mysql_real_escape_string( $key );
			break;
		}
	}
	
	$sql->insert_strings( mysql_real_escape_string( serialize( $strings ) ), $default );
	
	$id = mysql_insert_id();
}

?>